%Function to check is a matrix is definite negative or not.
%
%This function check if the given matrix A is definite negative checking its eigenvalues.
%
%Prototype: bool = definiteNegative(A)
%
%Input:     The A matrix to check.
%
%Output:    It returns 1 (TRUE) if A is definite negative.
%           It returns 0 (FALSE) if A is NOT definite negative.
%
%Author: Esposito Gianluca (N.Matr.056/100858)
%Revision Claudio Fantacci, Alessandro Martini.

function bool = definiteNegative( A )

bool = -1;
[row,col] = size(A);

% Is A a square matrix?
if (row ~= col)
   fprintf('Impossibile proseguire: matrice non quadrata\n');
   return;
end

% Checking the eigenvalues of matrix A we can say if A is definite positive
% or not
eigenvalues = eig(A);
for i = 1:length(eigenvalues)
    if eigenvalues(i) > 0
        bool = 0;
        return;
    end
end
bool = 1;   